// 投票
const voteMixin = {
	data(){
		return{
			//是否发起投票
			isVote: false,
			//定时器
			voteTimer: '',
			//投票剩余时间
			currentTime: 0,
			//学生投票信息
			voteInfo: [],
			//投票倒计时长
			voteTime: 60,
		}
	},
	computed:{
		
	},
	watch:{
		isVote(e){
			if(e){
				this.currentTime = this.voteTime
				this.voteTimer = setInterval(()=>{
					if(this.currentTime <= 0){
						this.isVote = false
					}else{
						this.currentTime--
					}
				}, 1000)
			}else{
				clearInterval(this.voteTimer)
			}
		}
	},
	onUnload() {
		clearInterval(this.voteTimer);
	},
	onHide() {
		clearInterval(this.voteTimer);
	},
	methods:{
		//发起投票
		beginVote(){
			let that = this;
			uni.showModal({
				content: '确认开始投票吗？',
				confirmText: '确认',
				success(e) {
					if(e.confirm){
						that.$http.request({
							url: 'api/LivePush/CreateVote',
							method: 'PUT',
							showLoading: false,
							data: {
								mainId: that.id,
								voteType: 1
							}
						})
					}
				}
			})
		},
		// 获取学生投票结果
		getVoteInfo(data){
			this.isVote = true;
			this.voteInfo = data.itemList;
		}
	}
}

export default voteMixin;